package mars.libs;

import java.lang.reflect.Type;
import java.util.Iterator;
import java.util.LinkedList;

import mars.beans.Film;
//import mars.beans.Film;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;


public class JsonParser {
	public void parseUserFromJson(String jsonData){
		Type listType = new TypeToken<LinkedList<Film>>(){}.getType();
		Gson gson = new Gson();
		LinkedList<Film> _films = gson.fromJson(jsonData, listType);
		for (Iterator<Film> iterator = _films.iterator(); iterator.hasNext();) {
			Film films = (Film) iterator.next();
			System.out.println("cname--->" + films.getCname());
			System.out.println("id---->" + films.getId());
		}
		
	}
	public LinkedList<Film> parseFilm(String jsonData){
		Type listType = new TypeToken<LinkedList<Film>>(){}.getType();
		Gson gson = new Gson();
		LinkedList<Film> _films = gson.fromJson(jsonData, listType);

		for (Iterator<Film> iterator = _films.iterator(); iterator.hasNext();) {
			Film film = (Film) iterator.next();
			System.out.println(film.toString());
		}
		return _films;
	}
	
}
